from django.shortcuts import render

from rest_framework.generics import ListAPIView

from . import models
from . import serializers
from luffyapi.settings import contants


# Create your views here.


class BannerAPIView(ListAPIView):
    """
    轮播图视图函数，展示所有的图片数据
    """
    # queryset = models.Banner.objects.filter(is_deleted=False, is_show=True)[:2]
    # 我们要做一个简单的配置
    queryset = models.Banner.objects.filter(is_deleted=False, is_show=True)[:contants.BANNER_LENGTH]
    serializer_class = serializers.BannerModelSerializer


# 顶部导航栏视图：展示所有的数据
class HeaderNavAPIView(ListAPIView):

    queryset = models.Nav.objects.filter(
        is_deleted=False,
        is_show=True,
        position=1
    ).order_by(
        '-orders'
    )[:contants.HEADER_NAV_LENGTH]
    serializer_class = serializers.NavModelSerializer


# 底部导航栏视图
class FooterNavAPIView(ListAPIView):
    queryset = models.Nav.objects.filter(
        is_deleted=False,
        is_show=True,
        position=2
    ).order_by(
        '-orders'
    )[:contants.HEADER_NAV_LENGTH]
    serializer_class = serializers.NavModelSerializer
